package com.augurit.gzcgwsp.ywcmn.web;

import javax.annotation.Resource;

import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;
import org.springframework.beans.factory.annotation.Autowired;
import org.springside.modules.orm.Page;
import org.springside.modules.web.struts2.Struts2Utils;

import com.augurit.common.base.action.CrudActionSupport;
import com.augurit.common.base.action.ExtCrudActionSupport;
import com.augurit.common.util.ExtUtils;
import com.augurit.common.util.lang.DateUtils;
import com.augurit.gzcgwsp.wfex.bi.service.IWfTemplateAttachmentRefServiceEX;
import com.augurit.gzcgwsp.ywcmn.service.IYwComPrintService;
import com.augurit.gzcgwsp.ywcmn.web.form.YwComPrintForm;
import com.augurit.wf.bi.service.IWfBusTemplateService;
import com.augurit.wf.bi.service.IWfTemplateAttachmentRefService;
import com.augurit.wf.bi.web.form.WfTemplateAttachmentRefForm;
import com.augurit.wf.common.constant.WfConstant;

@SuppressWarnings("serial")
@Results({
    @Result(name = CrudActionSupport.SUCCESS, location = "/gzcgwsp/ywcmn/YwComPrint/yw_print_yq.jsp"),
    @Result(name = "DBLCLICK_WIN", location = "/gzcgwsp/ywcmn/YwComPrint/yw_print_yq_win.jsp"),
    @Result(name = "PRINT_WIN", location = "/gzcgwsp/ywcmn/YwComPrint/yw_pwin.jsp"),
    @Result(name = WfConstant.PRINT, location = WfConstant.PRINT_JSP)
})
public class YwComYqprintAction extends ExtCrudActionSupport<YwComPrintForm> {

    @Autowired
    private IYwComPrintService ywComPrintService;
    
    @Autowired
    private IWfBusTemplateService wfBusTemplateService;
    
    @Autowired
    private IWfTemplateAttachmentRefService wfTemplateAttachmentRefService;
    
    @Autowired
    private IWfTemplateAttachmentRefServiceEX wfTemplateAttachmentRefServiceEX;
    
    private YwComPrintForm form;
    private Page<YwComPrintForm> page = new Page<YwComPrintForm>(15);
    private Page<WfTemplateAttachmentRefForm> tplpage = new Page<WfTemplateAttachmentRefForm>(10);
    private boolean suitPrint = false;//标志是否为套打
    /**
     * 
     * @return
     * @throws Exception
     */
    public String printData() throws Exception {
        ExtUtils.initPageFromExtGridParam(getRequest(), page);
        ywComPrintService.getPrintYqDataList(page, form);
        renderText(Struts2Utils.getJsonString(page, DateUtils.YEAR_MOUTH_DAY_));
        return null;
    }

    
    public String printList() throws Exception {
        ExtUtils.initPageFromExtGridParam(getRequest(), tplpage);
        wfTemplateAttachmentRefServiceEX.searchPrintTemplate(tplpage, form);
        renderText(Struts2Utils.getJsonString(tplpage, DateUtils.YEAR_MOUTH_DAY_));
        
        return null;
    }
    
    /**
     * 列出案件需要打印的受理通知书和延期通知书
     * @return
     * @throws Exception
     */
    public String searchYqPrintTemplate() throws Exception {
        ExtUtils.initPageFromExtGridParam(getRequest(), tplpage);
        wfTemplateAttachmentRefServiceEX.searchYqPrintTemplate(tplpage, form);
        renderText(Struts2Utils.getJsonString(tplpage, DateUtils.YEAR_MOUTH_DAY_));
        
        return null;
    }
    
    public String getList() throws Exception {
        ExtUtils.initPageFromExtGridParam(getRequest(), tplpage);
        ywComPrintService.getPrintTplList(page, form);
        renderText(Struts2Utils.getJsonString(page, DateUtils.YEAR_MOUTH_DAY_));
        
        return null;
    }
    
    public String taskInfo() throws Exception {
        return "PRINT_WIN";
    }
    
    public String info() throws Exception {
    	if(("dzgz".equals(form.getActivityName()) && "rqjyxkz_gdqy".equals(form.getTemplateCode()))
        		|| ("dzgz".equals(form.getActivityName()) && "rqjyxkz_pzqy".equals(form.getTemplateCode()))
        		|| ("dzgz".equals(form.getActivityName()) && "rqrsqjazwxqyzz".equals(form.getTemplateCode()))){
        		suitPrint = true;
        	}
        return "DBLCLICK_WIN";
    }
    
    @Override
    public String delete() throws Exception {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public String list() throws Exception {
        return CrudActionSupport.SUCCESS;
    }

    @Override
    protected void prepareModel() throws Exception {
        if (form == null) form = new YwComPrintForm();
    }

    @Override
    public String save() throws Exception {
        // TODO Auto-generated method stub
        return null;
    }

    public YwComPrintForm getModel() {
        // TODO Auto-generated method stub
        return form;
    }

}
